<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /*
        如果嫌麻烦的话,可以用库 js-cookie
        
        
       1. document.cookie 返回包含页面中所有有效 cookie 的字符串(根据域、路径、过期时间和安全设置)，以分号分隔
        name1=value1;name2=value2;name3=value3
     */

    // 封装一个操作


    class CookieUtil {
        static get(name) {
            let cookieName = `${encodeURIComponent(name)}=`, cookieStart = document.cookie.indexOf(cookieName),
                cookieValue = null;
            if (cookieStart > -1) {
                let cookieEnd = document.cookie.indexOf(";", cookieStart);
                if (cookieEnd == -1) {
                    cookieEnd = document.cookie.length;
                }
                cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length, cookieEnd));
            }
            return cookieValue;
        }

        static set(name, value, expires, path, domain, secure) {
            let cookieText =
                `${encodeURIComponent(name)}=${encodeURIComponent(value)}`
            if (expires instanceof Date) {
                cookieText += `; expires=${expires.toGMTString()}`;
            }
            if (path) {
                cookieText += `; path=${path}`;
            }
            if (domain) {
                cookieText += `; domain=${domain}`;
            }
            if (secure) {
                cookieText += "; secure";
            }
            document.cookie = cookieText;
        }

        static remove(name, path, domain, secure) {
            CookieUtil.set(name, "", new Date(0), path, domain, secure);
        }
    };

</script>
</body>
</html>